#import <UIKit/UIKit.h>
#import "sqlite3.h"
#import "ABContact.h"
#import "Statement.h"

@class Status;

#define kUserRelationSelf @"00"	//自己
#define kUserRelationBoth @"01" //相互关注
#define kUserRelationFollowing @"02" //我关注的人
#define kUserRelationFollower @"03" //粉丝，关注我的人
#define kUserRelationNone	@"04"	//没有关系
#define kUserRelationSilence @"05"  //默默关注

#define kUserStateValid @"VALID"        //已激活
#define kUserStateUnopen @"UNOPEN"      //注册未激活
#define kUserStateLocked @"LOCK"        //已锁住
#define kUserStateLocal @"LOCAL"        //未注册

#define kUserAccountOther 0     //user.account表中表示朋友
#define kUserAccountAccount 1   //user.account表中表示登录帐号
#define kUserAccountAccountCurrent 2    //user.account表中表示当前登录帐号

#define kUserIdLength  11

#define kUserSQLUser @"u.user_id, u.name, u.screen_name, u.location, u.description, u.url, u.followers_count, u.protected, u.profile_image_url_s, u.profile_image_url_m, u.profile_image_url_b, u.province_code, u.province_name, u.city_code, u.city_name, u.is_in_contacts, u.contact_name, u.phone_number, u.state, u.account, u.password"
#define kUserSQLUserRelation @"r.relation, r.remark"

@interface User : NSObject
{
	sqlite_int64    userId;
    NSString*   name;
	NSString*   screenName;
	NSString*   location;
	NSString*   description;
	NSString*   url;
	uint32_t    followersCount;
	//NSString*   profileImageUrl;
	NSString*	profileImageUrl_s;
	NSString*	profileImageUrl_m;
	NSString*	profileImageUrl_b;
    uint32_t    friendsCount;
    uint32_t    statusesCount;
    uint32_t    favoritesCount;
	
	NSString*	provinceCode;
	NSString*	provinceName;
	NSString*	cityCode;
	NSString*	cityName;
	
	BOOL		contact;
	NSString*	phone;
	NSString*   contactName;

    BOOL        notifications;
    BOOL        protected;
	NSString*	relation;
    NSString*   remark;
    NSString*   state;
    
    uint32_t    accountFlag;
    NSString*   password;
    
    NSString*   pyLetters;
    
	Status* status;
	
    NSArray* cards;
}

@property (nonatomic, assign) sqlite_int64  userId;
@property (nonatomic, retain) NSString* name;
@property (nonatomic, retain) NSString* screenName;
@property (nonatomic, retain) NSString* location;
@property (nonatomic, retain) NSString* description;
@property (nonatomic, retain) NSString* url;
@property (nonatomic, assign) uint32_t  followersCount;
//@property (nonatomic, retain) NSString* profileImageUrl;
@property (nonatomic, retain) NSString* profileImageUrl_s;
@property (nonatomic, retain) NSString* profileImageUrl_m;
@property (nonatomic, retain) NSString* profileImageUrl_b;
@property (nonatomic, assign) BOOL      protected;
@property (nonatomic, assign) uint32_t  friendsCount;
@property (nonatomic, assign) uint32_t  statusesCount;
@property (nonatomic, assign) uint32_t  favoritesCount;
@property (nonatomic, assign) BOOL      following;
@property (nonatomic, assign) BOOL      notifications;

@property (nonatomic, retain) NSString* provinceCode;
@property (nonatomic, retain) NSString* provinceName;
@property (nonatomic, retain) NSString* cityCode;
@property (nonatomic, retain) NSString* cityName;
@property (nonatomic, retain) NSString* phone;
@property (nonatomic, retain) NSString* relation;
@property (nonatomic, assign) BOOL contact; 
@property (nonatomic, retain) NSString* contactName;
@property (nonatomic, retain) NSString* remark;
@property (nonatomic, retain) NSString* state;

@property (nonatomic, readonly) NSString* remarkName;

@property (nonatomic, assign) uint32_t accountFlag;
@property (nonatomic, retain) NSString* password;

@property (nonatomic, retain) Status* status;

@property (nonatomic, retain) NSString* pyLetters;
@property (nonatomic, retain) NSArray* cards;

+ (User*)userWithId:(sqlite_int64)id;
+ (User*)userWithJsonDictionary:(NSDictionary*)dic;
+ (User*)userWithSearchResult:(NSDictionary*)dic;
+ (User*)userWithLocal;
+ (User*) userwithPhone:(NSString*)phone;

- (User*)initWithJsonDictionary:(NSDictionary*)dic;
- (User*)initWithSearchResult:(NSDictionary*)dic;
- (User*) initWithABContact:(ABContact*)contact;
- (id) initWithStatement:(Statement*)stmt withRelation:(BOOL)withRelation;

- (NSString*) toJsonString;

- (void)updateWithJSonDictionary:(NSDictionary*)dic;
- (void)updateDB:(BOOL)withRelation withName:(BOOL)withName withAccount:(BOOL)withAccount;
- (void) updateUser:(BOOL)withRelation withName:(BOOL)withName withAccount:(BOOL)withAccount;
- (void) insertUser:(BOOL)withRelation;
+ (void) updateAccountFlag:(NSInteger)flag userId:(long long)userId;
- (void) updateRelation;
+ (NSArray*) loadAllUsers;
+ (NSArray*) loadUsers:(NSString*)filterName filterPhone:(NSString*)filterPhone;
+ (User*) currentAccountUser;
+ (BOOL) isExistUser:(long long)userId;

@end
